<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > 
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:c="http://java.sun.com/jstl/core"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:fn="http://java.sun.com/jsp/jstl/functions"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:a="http://richfaces.org/a4j"
                xmlns:kiwi="http://www.kiwi-project.eu/jsf"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="/template/kiwi/template_1col.xhtml">

    <ui:define name="script">
        <s:remote include="KQBAction"/>
        <script src="KQB.js" type="text/javascript"></script>
        <script src="KQBNode.js" type="text/javascript"></script>
        <script src="KQBDragDrop.js" type="text/javascript"></script>
        <script src="KQBUtilities.js" type="text/javascript"></script>
        <script src="KQBStrings_En.js" type="text/javascript"></script>
        <script type="text/javascript" src="antlr3-all.js"></script>
        <script type="text/javascript" src="KWQLLexer.js"></script>
        <script type="text/javascript" src="KWQLParser.js"></script>
        <script src="/KiWi/a4j/g/3_3_1.GA/org/ajax4jsf/framework.pack.js" type="text/javascript"></script>
        <script src="/KiWi/a4j/g/3_3_1.GA/org/richfaces/ui.pack.js" type="text/javascript"></script>
        <script id="org.ajax4jsf.queue_script" type="text/javascript">if (typeof A4J != 'undefined') { if (A4J.AJAX) { with (A4J.AJAX) {if (!EventQueue.getQueue('formHdrSearch')) { EventQueue.addQueue(new EventQueue('formHdrSearch',null,null)) };if (!EventQueue.getQueue('formHdrNavigation')) { EventQueue.addQueue(new EventQueue('formHdrNavigation',null,null)) };if (!EventQueue.getQueue('org.richfaces.queue.global')) { EventQueue.addQueue(new EventQueue('org.richfaces.queue.global',null,null)) };}}};</script>
        <script type="text/javascript">window.RICH_FACES_EXTENDED_SKINNING_ON=true;</script><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript">
            window.onload = function() {
                KQB.Init();
            }  
        </script>
    </ui:define>

    <ui:define name="stylesheet">
        <link rel="stylesheet" type="text/css" href="stylesheet/kiwi/elements/search.css" />
    </ui:define>

    <ui:define name="link">

        <link rel="shortcut icon" href="home.xhtml#{facesContext.externalContext.requestContextPath}/favicon.ico" type="image/x-icon" />

    </ui:define>

    <ui:define name="center">


        <div class="box">

            <p:messages id="msgs" showDetail="false" />

            <noscript>

                <div style="background-color:red; color:white; margin: 10px; padding: 10px; font-size:20px; width:70%;">
			Welcome to the KiWi Query Builder. 
			The KQB is a DHTML application using JavaScript.
			JavaScript is currently disabled in Your browser. 
			To use the KQB, please enable the execution of scripts for this page
                </div>

            </noscript>

            <ul id="menulevel1" style="padding-left: 60px;">

                <li><a href="home.xhtml#">Resources</a>
                    <ul class="menulevel2" style="padding-left: 40px;">
                        <li><a href="home.xhtml#" title="ContentItem" alt="test" onclick="KQB.NewNode(KQB.NodeType.ContentItem); return false;">content item</a></li>
                        <li><a href="home.xhtml#" title="Fragment" onclick="KQB.NewNode(KQB.NodeType.Fragment); return false;">fragment</a></li>
                        <li><a href="home.xhtml#" title="Link" onclick="KQB.NewNode(KQB.NodeType.Link); return false;">link</a></li>
                        <li><a href="home.xhtml#" title="Tag" onclick="KQB.NewNode(KQB.NodeType.Tag); return false;">tag</a></li>
                    </ul>
                </li>

                <li><a href="home.xhtml#">Qualifiers</a>
                    <ul class="menulevel2"  style="padding-left: 40px;">
                        <li><a href="home.xhtml#">content item<span>&raquo;</span></a>
                            <ul class="menulevel3" style="padding-left: 40px;">
                                <li><a href="home.xhtml#" title="Author" onclick="KQB.NewNode(KQB.NodeType.Author); return false;">author</a></li>
                                <li><a href="home.xhtml#" title="Child" onclick="KQB.NewNode(KQB.NodeType.Child); return false;">child</a></li>
                                <li><a href="home.xhtml#" title="Created" onclick="KQB.NewNode(KQB.NodeType.Created); return false;">created</a></li>
                                <li><a href="home.xhtml#" title="Descendant" onclick="KQB.NewNode(KQB.NodeType.Descendant); return false;">descendant</a></li>
                                <li><a href="home.xhtml#" title="Fragment" onclick="KQB.NewNode(KQB.NodeType.Fragment); return false;">fragment</a></li>
                                <li><a href="home.xhtml#" title="LastEdited" onclick="KQB.NewNode(KQB.NodeType.LastEdited); return false;">lastEdited</a></li>
                                <li><a href="home.xhtml#" title="Link" onclick="KQB.NewNode(KQB.NodeType.Link); return false;">link</a></li>
                                <li><a href="home.xhtml#" title="NumberEdits" onclick="KQB.NewNode(KQB.NodeType.NumberEdits); return false;">numberEdits</a></li>
                                <li><a href="home.xhtml#" title="Tag" onclick="KQB.NewNode(KQB.NodeType.Tag); return false;">tag</a></li>
                                <li><a href="home.xhtml#" title="Text" onclick="KQB.NewNode(KQB.NodeType.Text); return false;">text</a></li>
                                <li><a href="home.xhtml#" title="Title" onclick="KQB.NewNode(KQB.NodeType.Title); return false;">title</a></li>
                                <li><a href="home.xhtml#" title="URI" onclick="KQB.NewNode(KQB.NodeType.URI); return false;">URI</a></li>
                            </ul>
                        </li>
                        <li><a href="home.xhtml#">fragment<span>&raquo;</span></a>
                            <ul class="menulevel3"  style="padding-left: 40px;">
                                <li><a href="home.xhtml#" title="Author" onclick="KQB.NewNode(KQB.NodeType.Author); return false;">author</a></li>
                                <li><a href="home.xhtml#" title="Child" onclick="KQB.NewNode(KQB.NodeType.Child); return false;">child</a></li>
                                <li><a href="home.xhtml#" title="Created" onclick="KQB.NewNode(KQB.NodeType.Created); return false;">created</a></li>
                                <li><a href="home.xhtml#" title="Descendant" onclick="KQB.NewNode(KQB.NodeType.Descendant); return false;">descendant</a></li>
                                <li><a href="home.xhtml#" title="Tag" onclick="KQB.NewNode(KQB.NodeType.Tag); return false;">tag</a></li>
                                <li><a href="home.xhtml#" title="URI" onclick="KQB.NewNode(KQB.NodeType.URI); return false;">URI</a></li>
                            </ul>
                        </li>
                        <li><a href="home.xhtml#">link<span>&raquo;</span></a>
                            <ul class="menulevel3"  style="padding-left: 40px;">
                                <li><a href="home.xhtml#" title="AnchorText" onclick="KQB.NewNode(KQB.NodeType.AnchorText); return false;">anchor text</a></li>
                                <li><a href="home.xhtml#" title="Tag" onclick="KQB.NewNode(KQB.NodeType.Tag); return false;">tag</a></li>
                                <li><a href="home.xhtml#" title="Target" onclick="KQB.NewNode(KQB.NodeType.Target); return false;">target</a></li>
                            </ul>
                        </li>
                        <li><a href="home.xhtml#">tag<span>&raquo;</span></a>
                            <ul class="menulevel3"  style="padding-left: 40px;">
                                <li><a href="home.xhtml#" title="Author" onclick="KQB.NewNode(KQB.NodeType.Author); return false;">author</a></li>
                                <li><a href="home.xhtml#" title="Created" onclick="KQB.NewNode(KQB.NodeType.Created); return false;">created</a></li>
                                <li><a href="home.xhtml#" title="Name" onclick="KQB.NewNode(KQB.NodeType.Name); return false;">name</a></li>
                                <li><a href="home.xhtml#" title="URI" onclick="KQB.NewNode(KQB.NodeType.URI); return false;">URI</a></li>
                            </ul>
                        </li>
                    </ul>
                </li>


                <li><a href="home.xhtml#">Operators</a>
                    <ul class="menulevel2"  style="padding-left: 40px;">
                        <li><a href="home.xhtml#" title="AND" onclick="KQB.NewNode(KQB.NodeType.AND); return false;">AND</a></li>
                        <li><a href="home.xhtml#" title="OR" onclick="KQB.NewNode(KQB.NodeType.OR); return false;">OR</a></li>
                        <li><a href="home.xhtml#" title="NOT" onclick="KQB.NewNode(KQB.NodeType.NOT); return false;">NOT</a></li>
                    </ul>
                </li>

                <li><a href="home.xhtml#">Other</a>
                    <ul class="menulevel2"  style="padding-left: 40px;">
                        <li><a href="home.xhtml#" title="Keyword" onclick="KQB.NewNode(KQB.NodeType.Keyword); return false;">Value</a></li>
                        <li><a href="home.xhtml#" title="Variable" onclick="KQB.NewNode(KQB.NodeType.Variable); return false;">Variable</a></li>
                    </ul>
                </li>

                <li><a href="home.xhtml#">Examples</a>
                    <ul class="menulevel2"  style="padding-left: 40px;">
                        <li><a href="home.xhtml#" onclick="KQB.Example(1); return false;" title="Search for wiki pages with 'KiWi' in the title and 'KWQL' somewhere in the text">Example 1</a></li>
                        <li><a href="home.xhtml#" onclick="KQB.Example(2); return false;" title="Search for wiki pages which are tagged 'KiWi' or have a child-page tagged 'KWQL'">Example 2</a></li>
                        <li><a href="home.xhtml#" onclick="KQB.Example(3);return false;" title="Search for wiki pages that contain the word 'KiWi' and do not contain the word 'KWQL'">Example 3</a></li>
                        <li><a href="home.xhtml#" onclick="KQB.Example(4);return false;" title="Get the number of tags that were given to wiki pages">Example 4</a></li>
                        <li><a href="home.xhtml#" onclick="KQB.Example(5);return false;" title="Get the number of tags that were given to wiki pages">Example 5</a></li>
                        <li><a href="home.xhtml#" onclick="KQB.Example(6);return false;" title="Get the number of tags that were given to wiki pages">Example 6</a></li>
                        <li><a href="home.xhtml#" onclick="KQB.Example(7);return false;" title="Get the number of tags that were given to wiki pages">Example 7</a></li>
                    </ul>
                </li>

            </ul>

            <table id="toppanel" style="width:75%">
                <tr>
                    <td>
                        <button onclick="KQB.Undo()">UNDO</button>
                        <button onclick="KQB.Redo()">REDO</button>
                    </td>
                    <td style="text-align:right;">
			    Saved Queries:
                        <select id="KQBSavedQueriesBox" style="width:200px"></select>
                        <button onclick="KQB.LoadSavedQuery()">Load</button>
                        <button onclick="KQB.DeleteSavedQuery()">Delete</button>
                        <button onclick="KQB.SaveCurrentQuery()">Save current query</button>
                    </td>
                </tr>
            </table>
            <div id="workspace"></div>
            <div id="tooltippane"></div>
            <div id="hintarea" style="width:75%; height:30px">
                <span id="hintpane"></span>
                <span id="resizearea"></span>
            </div>

            <table id="outputtable" style="clear:both;">
                <tr>
                    <td class="left">KWQL:</td>
                    <td style="width:40%">
                        <textarea id="outputpane" rows="5" style="width:97%"></textarea>
                    </td>
                    <td>
                        <table>
                            <tr>
                                <td>
                                    <button onclick="var inputstring = KQB.Outputpane.value;
						    if ( (inputstring.length == 0) || (KQB.ErrorNodes.length>0))
						    {
							alert ('Invalid query');
							return;
						    }
						    document.getElementById('kwqlSearchbarForm:searchField').value = inputstring;
						    document.getElementById('kwqlSearchbarForm:kwqlSearchbarButton').click();
                                            ">

						    Execute Query</button>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <button onclick="KQB.Parse()">Parse Query</button>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <button onclick="KQB.Clear()">Clear Workspace</button>
                                </td>
                            </tr>
                        </table>

                    </td>
                    <td>
                        <span id="parsererrorpane" style="color:red;"></span>
                    </td>
                </tr>
            </table>
            <h:form id="kwqlSearchbarForm">
                <div id="searchbar">
                    <h:inputHidden value="#{kwqlAction.searchEngine.KWQLQuery}" id="searchField"/>
                    <!--
	                    <rich:suggestionbox for="searchField" suggestionAction="#{kwqlaAction.searchEngine.autocomplete}" var="result">
		                    <h:column>
		                        <h:outputText value="#{result}" />
		                    </h:column>
	                    </rich:suggestionbox>
	                    -->
                    <a:commandButton
                        action="#{kwqlAction.searchEngine.runSearch()}"

                        id="kwqlSearchbarButton" size="1"
                        value=" "
                        image="#{facesContext.externalContext.requestContextPath}/spacer.gif"
                        reRender="#{kwqlAction.renderedSearchPageParts()}"
                        />


                </div>

                <div id="search_size">

                    <s:fragment rendered="#{kwqlAction.searchEngine.searchResults.resultCount > 0}">

                        <!-- number of results -->
                        <s:span id="nrOfResults">
                            <h:outputText value="Results #{(kwqlAction.searchEngine.page-1) * kwqlAction.searchEngine.pageSize + 1} - #{kwqlAction.searchEngine.min(kwqlAction.searchEngine.searchResults.resultCount, (kwqlAction.searchEngine.page * kwqlAction.searchEngine.pageSize))} of totally #{kwqlAction.searchEngine.searchResults.resultCount} ordered by " />
                            <h:outputText value=" " />
                        </s:span>

                        <!-- searchfield -->
                        <rich:inplaceSelect id="searchorderby" value="#{kwqlAction.searchEngine.orderBy}" defaultLabel="Click here to edit">
                            <a:support event="onviewactivated" action="#{kwqlAction.searchEngine.getResults(true)}" reRender="searchorderby,searchresults" />
                            <s:selectItems value="#{kwqlAction.searchEngine.orderBys}" var="orderBy" label="#{orderBy}" />
                        </rich:inplaceSelect>

                        <h:outputText value=" " />

                        <!-- order -->
                        <rich:inplaceSelect id="searchorder" value="#{kwqlAction.searchEngine.order}" defaultLabel="Click here to edit">
                            <a:support event="onviewactivated" action="#{kwqlAction.searchEngine.getResults(true)}" reRender="searchorder,searchresults" />
                            <s:selectItems value="#{kwqlAction.searchEngine.orders}" var="order" label="#{kiwi.messages.getProperty(order)}" />
                        </rich:inplaceSelect>

                    </s:fragment>

                    <s:fragment rendered="#{kwqlAction.searchEngine.searchResults.resultCount == 0}">
                        <h:outputText value="no Results" />
                    </s:fragment>

                </div>

                <!--  the search results in the left column -->
                <s:div id="searchresults" style="clear:left;">
                    <c:forEach items="#{kwqlAction.searchEngine.currentResults.results}" var="r" >
                        <hr style="clear:both;"/>
                        <!-- include template to show one result item. -->
                        <ui:include src="home.xhtml#{kiwi.wiki.ui.layoutAction.getSearchResultItemTemplate(r.item)}">
                            <ui:param name="ci" value="#{r.item}" />
                            <ui:param name="mode" value="#{kiwi.wiki.ui.layoutAction.viewMode}" />
                            <ui:param name="score" value="#{r.score}" />
                            <ui:param name="ceq" value="#{r.ceq}" />
                            <ui:param name="preview" value="#{kwqlAction.searchEngine.getPreview(r.item)}"/>
                        </ui:include>
                        <br/>
                    </c:forEach>
                </s:div>

                <s:div id="resultNavigation">
                    <s:fragment rendered="#{kwqlAction.searchEngine.pages.size > 1}">
                        <!-- result navigation -->
                        <span class="back">
                            <a:commandLink action="#{kwqlAction.searchEngine.prevPage()}" value="back" reRender="#{kwqlAction.renderedSearchPageParts()}" disabled="#{kwqlAction.searchEngine.page eq 1}" />
                        </span>

                        <c:forEach items="#{kwqlAction.searchEngine.pages}" var="page">
                            <s:span rendered="#{ page eq 1 and kwqlAction.searchEngine.page > 5 }">
                                <a:commandLink action="#{kwqlAction.searchEngine.setPage(page)}"
                                               value="#{page}"
                                               reRender="#{kwqlAction.renderedSearchPageParts()}" />
                                <h:outputText value=" ... " />
                            </s:span>

                            <s:span styleClass="selected" rendered="#{page eq kwqlAction.searchEngine.page}">
                                <h:outputText value="#{page}" />
                            </s:span>

                            <s:span rendered="#{ (page eq kwqlAction.searchEngine.pages.size) and ((page-kwqlAction.searchEngine.page) > 5) }">
                                <h:outputText value=" ... " />
                                <a:commandLink
                                    action="#{kwqlAction.searchEngine.setPage(page)}"
                                    value="#{page}"
                                    reRender="#{kwqlAction.renderedSearchPageParts()}" />
                            </s:span>

                            <s:span rendered="#{(page != kwqlAction.searchEngine.page) and (5 > page - kwqlAction.searchEngine.page) and (page - kwqlAction.searchEngine.page > -5) }">
                                <a:commandLink
                                    action="#{kwqlAction.searchEngine.setPage(page)}"
                                    value="#{page}"
                                    reRender="#{kwqlAction.renderedSearchPageParts()}" />
                            </s:span>

                            <h:outputText value=" " />
                        </c:forEach>
                        <span class="next">
                            <a:commandLink action="#{kwqlAction.searchEngine.nextPage()}" value="next" reRender="#{kwqlAction.renderedSearchPageParts()}" disabled="#{kwqlAction.searchEngine.page eq kwqlAction.searchEngine.pages.size}" />
                        </span>
                    </s:fragment>
                </s:div>

            </h:form>
        </div>
        <div id="footer">
		Powered by <a href="http://www.kiwi-project.eu">KiWi - Knowledge in a Wiki</a> (version @version@).
        </div>

    </ui:define>
</ui:composition>   
